package com.cskaoyan.market.service.admin.impl;

import com.cskaoyan.market.db.domain.MarketCategory;
import com.cskaoyan.market.db.domain.MarketCategoryExample;
import com.cskaoyan.market.db.mapper.MarketCategoryMapper;
import com.cskaoyan.market.service.admin.MarketCategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author：Katherine
 * @Package：com.cskaoyan.market.service.impl
 * @Project：java-project1
 * @name：CategoryServiceImpl
 * @Date：2023/5/9 23:17
 * @Filename：CategoryServiceImpl
 */
@Service
public class MarketCategoryServiceImpl implements MarketCategoryService {

    @Autowired
    MarketCategoryMapper marketCategoryMapper;
    // 查询商品全部的一级类目
    @Override
    public List<MarketCategory> selectAllOneCategory() {

        // 构建条件，一级类目，过滤掉逻辑删除的
        MarketCategoryExample marketCategoryExample = new MarketCategoryExample();
        marketCategoryExample.or().andLevelEqualTo("L1").andLogicalDeleted(true);
        // 查询出全部的一级类目
        List<MarketCategory> marketOneCategories = marketCategoryMapper.selectByExample(marketCategoryExample);
        // 关闭sqlSession连接

        return marketOneCategories;
    }

    // 再查询出全部的二级类目
    @Override
    public List<MarketCategory> selectAllTwoCategory() {

        // 构建条件，二级类目，过滤掉逻辑删除的
        MarketCategoryExample marketCategoryExample = new MarketCategoryExample();
        marketCategoryExample.or().andLevelEqualTo("L2").andLogicalDeleted(true);
        // 查询出全部的二级类目
        List<MarketCategory> marketTwoCategories = marketCategoryMapper.selectByExample(marketCategoryExample);
        // 关闭sqlSession连接

        return marketTwoCategories;
    }

    // 进行类目的新增
    @Override
    public void insertMarketCategory(MarketCategory marketCategory) {

        // 进行插入
        marketCategoryMapper.insertSelective(marketCategory);

    }

    // 通过id进行修改
    @Override
    public int updateMarketCategoryById(MarketCategory marketCategory) {

        // 进行修改
        int flag = marketCategoryMapper.updateByPrimaryKeySelective(marketCategory);

        return flag;
    }

    // 直接通过id进行删除
    @Override
    public void deleteMarketCategoryById(MarketCategory marketCategory) {

        // 直接通过id进行修改deleted
        marketCategoryMapper.updateByPrimaryKeySelective(marketCategory);

    }
}
